<?php

class MYSQLConnection {
	private $dbserver;
	private $dbname;
	private $dbuser;
	private $dbpass;
	private $dblink;

	function __construct($dbpass = "", $dbuser = "root", $dbname = "test", $dbserver = "localhost" ) {
		$this->dbserver = $dbserver;
		$this->dbname = $dbname;
		$this->dbuser = $dbuser;
		$this->dbpass = $dbpass;
	}

	function connect () {
		if( !$this->dblink = mysql_pconnect ( $this->dbserver, $this->dbuser, $this->dbpass)) {
			trigger_error( mysql_error(), E_USER_ERROR);
			return false;
		}

		if( !mysql_select_db ( $this->dbname, $this->dblink)) {
			trigger_error( mysql_error(), E_USER_ERROR);
			return false;
		}
		
		mysql_query('SET NAMES "utf8"', $this->dblink);
		return true;
	}

	function free() {
		mysql_free_result();
	}

	function query( $query) {;
		return mysql_query($query, $this->dblink);
// 		return mysql_query($query, $this->dblink) or die (mysql_error());
	}

	function disconnect() {
		mysql_close( $this->dblink) ;
	}
}
?>
